<template>
  <div class="search-content">
    <div class="search-head">
      <div class="search-input">
        <span class="font_family icon-sousuo"></span>
        <input
          type="text"
          class="input"
          v-model="searchValue"
          @keydown.enter="getData"
          placeholder="报工、服务单等"
        />
        <span
          class="font_family icon-shanchu"
          v-show="isClear"
          @click="searchValue = ''"
        ></span>
      </div>
      <div class="search-tabs">
        <div
          class="item"
          :class="type == '1' ? 'active' : ''"
          @click="type = '1'"
        >
          综合
        </div>
        <div
          class="item"
          :class="type == '2' ? 'active' : ''"
          @click="type = '2'"
        >
          服务单
        </div>
        <div
          class="item"
          :class="type == '3' ? 'active' : ''"
          @click="type = '3'"
        >
          报工
        </div>
        <!-- <div class="item" :class="type == 'declaration' ? 'active' : ''" @click="type = 'declaration'">报表</div> -->
        <div
          class="item"
          :class="type == '4' ? 'active' : ''"
          @click="type = '4'"
        >
          消息
        </div>
      </div>
    </div>
    <div class="search-list">
      <!-- 报工审批 -->
      <div v-if="result && result.report && result.report.length>0 && type == 1" class="result-item">
        <div class="result-title">报工审批</div>
        <div
          v-for="(item, index) in result.report"
          :key="index"
          @click="goReportdetail(item.id)"
        >
          <div class="content ol-item">
            <div class="info">
              <div class="title">{{ item.project_name }}</div>
              <div class="time">{{ item.report_date }}</div>
            </div>
            <div class="more-info">
              <div class="desc">
                {{ item.title }}
              </div>
              <div class="hour">{{ item.time }}</div>
            </div>
          </div>
          <div class="result-desc">
            <div class="name"></div>
            <div v-if="item.status == 2" class="intro">待审核</div>
            <div v-if="item.status == 3" class="intro">已审核</div>
            <div v-if="item.status == 4" class="intro">审核未通过</div>
          </div>
        </div>
      </div>
      <div v-if="result && result.length>0 && type == 3" class="result-item">
        <div class="result-title">报工审批</div>
        <div
          v-for="(item, index) in result"
          :key="index"
          @click="goReportdetail(item.id)"
        >
          <div class="content ol-item">
            <div class="info">
              <div class="title">{{ item.project_name }}</div>
              <div class="time">{{ item.report_date }}</div>
            </div>
            <div class="more-info">
              <div class="desc">
                {{ item.title }}
              </div>
              <div class="hour">{{ item.time }}</div>
            </div>
          </div>
          <div class="result-desc">
            <div class="name"></div>
            <div v-if="item.status == 2" class="intro">待审核</div>
            <div v-if="item.status == 3" class="intro">已审核</div>
            <div v-if="item.status == 4" class="intro">审核未通过</div>
          </div>
        </div>
      </div>
      <!-- 服务单 -->
      <div v-if="result && result.service && result.service.length>0 && type == 1" class="result-item">
        <div class="result-title">团队服务单</div>
        <div
          v-for="(item, index) in result.service"
          :key="index"
          @click="goServicedetail(item.id)"
        >
          <div class="content ol-item">
            <div class="info">
              <div class="title">{{ item.subject }}</div>
              <div class="time">{{ item.date }}</div>
            </div>
            <div class="more-info">
              <div class="desc">
                {{ item.title }}
              </div>
              <!-- <div class="hour">18h</div> -->
            </div>
          </div>
          <!-- <div class="result-desc">
            <div class="name">张三</div>
            <div class="intro"></div>
          </div> -->
        </div>
      </div>
      <div v-if="result && result.length>0 && type == 2" class="result-item">
        <div class="result-title">团队服务单</div>
        <div
          v-for="(item, index) in result"
          :key="index"
          @click="goServicedetail(item.id)"
        >
          <div class="content ol-item">
            <div class="info">
              <div class="title">{{ item.subject }}</div>
              <div class="time">{{ item.date }}</div>
            </div>
            <div class="more-info">
              <div class="desc">
                {{ item.title }}
              </div>
              <!-- <div class="hour">18h</div> -->
            </div>
          </div>
          <!-- <div class="result-desc">
            <div class="name">张三</div>
            <div class="intro"></div>
          </div> -->
        </div>
      </div>
      <!-- 报工审批 -->
      <!-- <div class="result-item">
        <div class="result-title">IT服务单提数报表</div>
        <div class="content">
          <div class="table-data">
            <div class="name">张国寿</div>
            <div class="line">
              <div class="over-line" style="width: 60%">余6h</div>
              <div class="diver"></div>
            </div>
          </div>
          <div class="table-data">
            <div class="name">李四</div>
            <div class="line over">
              <div class="over-line">超1h</div>
              <div class="diver"></div>
            </div>
          </div>
        </div>
      </div> -->
    </div>
    <goback></goback>
    <no-data v-if="!result || result.length==0" :noDataText="noDataText"></no-data>
  </div>
</template>
<script>
import { search } from "@/api/home.js";
import Goback from '@/components/goback.vue';
import NoData from "@/components/noData";
export default {
  components:{
    Goback,
    NoData
  },
  data() {
    return {
      searchValue: "",
      type: 1,
      result: "",
      isClear:false,
      noDataText:'暂无数据',
    };
  },
  watch: {
    searchValue(newVal) {
      // console.log(newVal);
      if(newVal == ''){
        this.isClear = false;
        this.getData();
      }else{
        this.isClear = true
      }
      
    },
    type() {
      this.getData();
    },
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      search({
        search: this.searchValue,
        type: this.type,
      }).then((res) => {
        console.log(res);
        if (res.status == "success") {
          this.result = res.data;
        }
      });
    },
    //服务单详情
    goServicedetail(listid) {
      this.$router.push({
        path: "/service/detail",
        query: {
          id: listid,
        },
      });
    },
    goReportdetail(id) {
      this.$router.push({
        path: "/ol/detail",
        query: {
          id: id,
        },
      });
    },
  },
};
</script>
<style lang="less" scoped>
.search-content {
  background: #f7f9f9;
  padding-top: 102px;
  min-height: calc(100vh - 112px - env(safe-area-inset-bottom));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
// search-tabs
.search-head {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #fff;
  .search-input {
    position: relative;
    margin: 15px;
    .input {
      width: 100%;
      display: block;
      height: 36px;
      padding: 6px 12px 6px 36px;
      border: 0;
      box-sizing: border-box;
      background: #f8f8f8;
      border-radius: 7px;
      outline: none;
      -webkit-tap-highlight-color: transparent;
      &:focus {
        outline: none;
      }
    }
    .icon-sousuo {
      position: absolute;
      top: 50%;
      left: 10px;
      margin-top: -7px;
      font-size: 15px;
      color: #8f92a1;
    }
    .icon-shanchu {
      position: absolute;
      top: 7px;
      padding: 10px;
      right: 5px;
      margin-top: -7px;
      font-size: 15px;
      color: #8f92a1;
    }
  }
  // tabs
  .search-tabs {
    display: flex;
    height: 40px;
    margin-top: 10px;
    .item {
      flex: 1;
      text-align: center;
      line-height: 40px;
      font-size: 13px;
      color: #313541;
      &.active {
        font-size: 14px;
        font-weight: bold;
        position: relative;
        color: #009966;
        &:after {
          position: absolute;
          content: "";
          left: 50%;
          bottom: 0;
          width: 20px;
          height: 1px;
          margin-left: -10px;
          background: #009966;
        }
      }
    }
  }
}
// search-list
.search-list {
  padding: 10px 0;
  .result-item {
    background: #fff;
    margin-bottom: 10px;
    .result-title {
      padding-left: 15px;
      height: 26px;
      line-height: 26px;
      font-size: 12px;
      color: #8f92a1;
      border-bottom: 1px solid #f2f2f2;
    }
    .content {
      margin: 0 15px;
      border-bottom: 1px solid #f2f2f2;
    }
    .result-desc {
      display: flex;
      height: 30px;
      line-height: 30px;
      font-size: 12px;
      padding: 0 15px;
      justify-content: space-between;
      .name {
        color: #313541;
      }
      .intro {
        color: #0041c4;
      }
    }
    // ol-item
    .ol-item {
      height: 78px;
      background: #fff;
      &:last-child {
        border-bottom: 0;
      }
      .info {
        display: flex;
        padding-top: 14px;
        .title {
          flex: 1;
          height: 22px;
          font-size: 16px;
          font-weight: bold;
          line-height: 22px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .time {
          width: 80px;
          height: 22px;
          line-height: 22px;
          color: #939dad;
          font-size: 12px;
          text-align: right;
        }
      }
      .more-info {
        display: flex;
        margin-top: 6px;
        .desc {
          flex: 1;
          font-size: 12px;
          height: 17px;
          line-height: 17px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .hour {
          width: 50px;
          height: 17px;
          line-height: 17px;
          font-size: 17px;
          font-weight: bold;
          color: #009966;
          text-align: right;
        }
      }
    }
    // table-data
    .table-data {
      display: flex;
      padding: 0 15px;
      font-size: 12px;
      margin: 18px 0;
      .name {
        width: 60px;
        color: #011445;
      }
      .over-line {
        height: 15px;
        background: #009966;
        color: #ffffff;
        border-radius: 3px;
        text-align: right;
        padding-right: 10px;
        box-sizing: border-box;
      }
      .diver {
        position: absolute;
        left: 70%;
        top: 0;
        height: 15px;
        width: 1px;
        background: #d2d5d5;
      }
      .line {
        position: relative;
        flex: 1;
        height: 15px;
        border-radius: 3px;
        background: #f7f9f9;
        &.over {
          .over-line {
            background: #e6b522;
          }
          .diver {
            background: #fff;
          }
        }
      }
    }
  }
}
</style>